//=================================================================================================
// DESC: commands for parallel programming (ATMEL AVR)
// AUTHOR: wiRe (http://w1r3.de/)
// DATE: 07/04/2006
//
// Copyright (c)2006 wiRe
//=================================================================================================
#pragma once
#include "pport.h"


class PPerror
{
public:
  PPerror(const char *lpszError) {this->lpszError = lpszError;};
  const char *what() {return lpszError;}

private:
  const char *lpszError;
};


class PProg
{
public:
  short get_port() {return port.BasePort;}

  void init(short baseport = -1);
  void terminate();

  int read_signature();
  int read_fuses();
  short read_lockbits();

  void write_fuses(int fuses);
  void chip_erase();

private:
  short read_data();
  void write_data(short d);

  void cmd(short id);
  void addr_lo(short addr);
  void data_lo(short data);
  short rx();

  void wait_while_busy();
  void wait_for_stable_signal();

private:
  PPort port;
};